Bouncing Circle and Square Screen Painter

Charlie Veniot 1st October 2022 at 3:30am
' Based on https://qb64phoenix.com/qb64wiki/index.php/DISPLAY

SCREEN 12
_ALERT("INSTRUCTIONS:\n\nPress the space bar at any time to pause the program.\n\nTo resume the paused program, press any key.\n\nPress the escape key to restart.")
main:
x = int(rnd * 640): y = int(rnd*480)              'start position
dx = 3 : dy = 3             'number of pixel moves per loop
s = int(rnd * 6) + 15  ' 15 to 20
IF int(RND*2) = 1 THEN DX = - DX
IF int(RND*2) = 1 THEN DY = - DY
DO
    x = x + dx: y = y + dy
    IF x < 0 OR x > 639 THEN dx = -dx 'limit columns and reverse column direction each side
    IF y < 0 OR y > 479 THEN dy = -dy 'limit rows and reverse row direction top or bottom
    line (x-s, y-s)-(x+s, y+s),14,BF
    CIRCLE (x, y), 20, 6, , , ,F  'draw new circle at new position
    px = x: py = y        'save older coordinates to erase older circle next loop
    _DISPLAY                'after new circle is set, show it
	 THIS_KEY$ = INKEY$
	 IF THIS_KEY$ = " " THEN CONTINUE$ = INPUT$(1)
LOOP UNTIL THIS_KEY$ = CHR$(27) 
cls
WHILE INKEY$ = CHR$(27) : WEND
goto main